package com.example.test1.config;

import dev.langchain4j.memory.chat.ChatMemoryProvider;
import dev.langchain4j.memory.chat.MessageWindowChatMemory;
import dev.langchain4j.service.spring.AiService;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import static dev.langchain4j.service.spring.AiServiceWiringMode.EXPLICIT;

//自定义配置类,提供隔离的聊天记忆
@Configuration
public class SeparateChatAssistantConfig {


    //方法名就是注解中的参数名:
//    @AiService(
//            wiringMode = EXPLICIT,
//
//            chatMemoryProvider = "chatMemoryProvider"
//    )
    //自定义记忆区提供者,在助手注解@AiService中使用，
    @Bean
    ChatMemoryProvider chatMemoryProvider() {
        //构建一个记忆区MessageWindowChatMemory对象,指定记忆区大小，并返回
        return memoryId -> MessageWindowChatMemory.builder()
                .id(memoryId)
                .maxMessages(10)
                .build();
    }
}
